package com.xixi.demo.service;

import com.xixi.demo.mapper.BlogMapper;
import com.xixi.demo.model.BlogInfo;
import com.xixi.demo.model.PageRequest;
import com.xixi.demo.model.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BlogService {
    @Autowired
    private BlogMapper blogMapper;

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }

    public List<BlogInfo> selectAll() {
        return blogMapper.selectAll();
    }

    public PageResult<BlogInfo> getBookListByPage(PageRequest pageRequest){
        Integer count = blogMapper.count();
        List<BlogInfo> blogs = blogMapper.getBookListByPage(pageRequest.getOffset(), pageRequest.getPageSize());
        return new PageResult<>(count, blogs, pageRequest);
    }

    public BlogInfo getBlogDetail(Integer blogId) {
        return blogMapper.selectById(blogId);
    }

    public Integer addBlog(BlogInfo blogInfo) {
        return blogMapper.insertBlog(blogInfo);
    }

    public Integer deleteBlog(Integer blogId) {
        return blogMapper.deleteBlog(blogId);
    }
}
